<%String path = request.getContextPath();
  String basePath = request.getScheme() + "://"
          + request.getServerName() + ":" + request.getServerPort()
          + path + "/";
%>
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html lang="zh-cn">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="<%=path%>/media/js/jquery.1.9.js" ></script>
    <title>简易设备资产管理系统</title>
   
  </head>
  <body>
    <div style="margin-left: auto;margin-right: auto;">
      <h2>简易设备资产管理系统</h2>
      <br>

      <table>
        <tr>
          <td>用户名*</td>
          <td colspan="3">
            <input type="text" name="username" id="username" >
          </td>
        </tr>
        <tr>
          <td>密码*</td>
          <td colspan="3">
            <input type="password" name="password" id="password" >
          </td>
        </tr>
        <tr>
          <td>密码确认*</td>
          <td colspan="3">
            <input type="password" name="repassword" id="repassword" >
          </td>
        </tr>
        <tr>
          <td>真实姓名</td>
          <td colspan="3">
            <input type="text" name="realName" id="realName" >
          </td>
        </tr>
        <tr>
          <td>电话</td>
          <td colspan="3">
            <input type="text" name="tel" id="tel" >
          </td>
        </tr>
        <tr>
          <td>邮箱</td>
          <td colspan="3">
            <input type="text" name="email" id="email" >
          </td>
        </tr>
        <tr>
          <td colspan="2"><button onclick="newUser()" >注册</button></td>
          <td colspan="2"><a href="javascript:history.go(-1)"><button>返回</button></a></td>
        </tr>
        <tr>
          <td colspan="4" ><p id="notice" style="display: none;" ></p></td>
        </tr>
      </table>

  </div>
  </body>
  <script>
    function newUser(){

      var loginName = $("#username").val();
      var pwd = $("#password").val();
      var repwd = $("#repassword").val();
      var realName = $("#realName").val();
      var tel = $("#tel").val();
      var email = $("#email").val();

      var notice = $("#notice");
      var path = "<%=path%>";

      if (isNull(loginName)) {
        notice.text("用户名不能为空");
        $("#username").focus();
      }
      else if (pwd != repwd) {
        notice.text("两次密码不一样");
        $("#repassword").focus();
      } else {
        $.ajax({
          url : "doRegister.html",
          type : "post",
          dataType : "json",
          data : {
            loginName : loginName,
            realName : realName,
            password : pwd,
            tel : tel,
            email : email
          },
          success : function(rd) {
            if (rd) {
              alert("注册成功");
              $.ajax({
                url:'doLogin.html',
                type:'get',
                dataType:'json',
                data:{
                  username : loginName,
                  password : pwd
                },
                success : function(rd) {
                  if (rd) {
                    window.location.href = path + "/userIndex.html";
                  }
                }

              })
            }
          }

        })
      }


    }
    function isNull(obc) {
      return (obc == null || obc.length <= 0);
    }
  </script>
</html>